@extends('admin.layouts.app')

@section('right-content')
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>编辑菜单</legend>
    </fieldset>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">父级菜单</label>
            <div class="layui-input-block">
                <select name="parent_id" lay-verify="">
                    <option value="0">顶级菜单</option>
                    @foreach ($topMenus as $topMenu)
                        <option value="{{ $topMenu->id }}" @if ($topMenu->id == $menu->parent_id) selected @endif>{{ $topMenu->title }}</option>
                    @endforeach
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{{ $menu->title }}" lay-verify="required" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">路由</label>
            <div class="layui-input-inline">
                <input type="text" name="route" value="{{ $menu->route }}" lay-verify="required" placeholder="请输入路由" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">菜单图标</label>
            <div class="layui-input-inline">
                <input type="text" name="icon" value="{{ htmlspecialchars($menu->icon) }}" lay-verify="" placeholder="请输入菜单图标" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">辅助文字<i class="layui-icon">&#xe60c;&#xe6c6;</i> </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">菜单描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="description">{{ $menu->description }}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="listorder" value="{{ $menu->listorder }}" lay-verify="" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否为菜单</label>
            <div class="layui-input-block">
                <input type="radio" name="is_menu" value="1" title="是" @if ($menu->is_menu == 1) checked @endif>
                <input type="radio" name="is_menu" value="0" title="否" @if ($menu->is_menu == 0) checked @endif>
            </div>
        </div>

       <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" @if ($menu->status == 1) checked @endif>
                <input type="radio" name="status" value="0" title="停用" @if ($menu->status == 0) checked @endif>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('menus.update', ['id' => $menu->id]) }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
   layui.use('form', function(){
       var form = layui.form;

      form.on('submit(sub)', function(data){
        var url = $(this).attr('data-url');
        commonAjaxSubmit(url, 'PUT');

      })
    });
</script>
@endsection